package fourThread;


import consumer.Consumer;
import producer.Producer;
import queue.Queue1;

/**
 * @author Xu,
 * @data 2020/12/20，
 * @time 14:45
 */
public class FourThread{
    public static void main(String[] args) throws InterruptedException {
        long start = System.currentTimeMillis();
        Queue1 queue = new Queue1();
        Producer producer1 = new Producer(queue,500000);
        Producer producer2 = new Producer(queue,500000);
        Thread t1 = new Thread(producer1);
        Thread t2 = new Thread(producer2);
        Consumer consumer1 = new Consumer(queue, 250000);
        Consumer consumer2 = new Consumer(queue, 250000);
        Consumer consumer3 = new Consumer(queue, 250000);
        Consumer consumer4 = new Consumer(queue, 250000);
        Thread t3 = new Thread(consumer1);
        Thread t4 = new Thread(consumer2);
        Thread t5 = new Thread(consumer3);
        Thread t6 = new Thread(consumer4);
        t1.start();
        t2.start();
        t3.start();
        t4.start();
        t5.start();
        t6.start();
        t1.join();
        t2.join();
        t3.join();
        t4.join();
        t5.join();
        t6.join();
        System.out.println(producer1.getCount());
        System.out.println(producer2.getCount());
        System.out.println(consumer1.getCount());
        System.out.println(consumer2.getCount());
        System.out.println(consumer3.getCount());
        System.out.println(consumer4.getCount());
        long end = System.currentTimeMillis();
        System.out.println("runtime: " + (end-start)/1000.0 + "s");
    }
}
